import { addRule, removeRule, rule, updateRule } from '@/services/ant-design-pro/api';
import { instance } from '@/services/jy-api/api';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components';
import {
  FooterToolbar,
  ModalForm,
  PageContainer,
  ProDescriptions,
  ProFormText,
  ProFormTextArea,
  ProTable,
} from '@ant-design/pro-components';
import { Button, Drawer, Input, message } from 'antd';
import React, { useRef, useState } from 'react';


/**
 *  Delete node
 * @zh-CN 删除节点
 *
 * @param selectedRows
 */
const handleRemove = async (selectedRows: API.RuleListItem[]) => {
  const hide = message.loading('正在删除');
  if (!selectedRows) return true;
  try {
    await removeRule({
      key: selectedRows.map((row) => row.key),
    });
    hide();
    message.success('Deleted successfully and will refresh soon');
    return true;
  } catch (error) {
    hide();
    message.error('Delete failed, please try again');
    return false;
  }
};

const TableList: React.FC = () => {
  const actionRef = useRef<ActionType>();
  const columns: ProColumns<API.RuleListItem>[] = [
    {
      title: '部门',
      dataIndex: 'department_name',
      hideInSearch: true
    },
    {
      title: '在线人员',
      dataIndex: 'name',
      valueType: 'textarea',
      hideInSearch: true,
      render: (node: any) => {
        return node.join()
      }
    },
  ];

  const request = (params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
    options?: { [key: string]: any },) => instance('/index/Screen/onlineNumber', {
      method: 'GET',
      params: {
        ...params
      },
    })

  return (
    <PageContainer>
      <ProTable<API.RuleListItem, API.PageParams>
        actionRef={actionRef}
        rowKey="key"
        search={false}
        request={request}
        columns={columns}
      />
    </PageContainer>
  );
};

export default TableList;
